package org.duanyu.shopping_common.result;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.io.Serializable;

@Data
@AllArgsConstructor
public class BaseResult<T> implements Serializable {
    //状态吗(成功：200,失败：其他)
    private Integer code;
    //提示消息
    private String message;
    //返回数据
    private T data;

    //构建普通成功结果
    public static <T> BaseResult<T> success() {
        return new BaseResult<>(CodeEnum.SUCCESS.getCode(), CodeEnum.SUCCESS.getMessage(), null);
    }

    //带有数据的成功结果
    public static <T> BaseResult<T> success(T data) {
        return new BaseResult<>(CodeEnum.SUCCESS.getCode(), CodeEnum.SUCCESS.getMessage(), data);
    }

}
